package com.youlu.campus.admin.activity.controller;

import com.youlu.campus.activity.entity.ActivityLotteryPrize;
import com.youlu.campus.activity.entity.ActivityLotteryPrizeNameVo;
import com.youlu.campus.activity.entity.ActivityLotteryPrizeQueryVo;
import com.youlu.campus.activity.service.ActivityLotteryPrizeService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 奖品服务接口
 *
 * @Description: AdminActivityLotteryPrizeController
 * @Date 2025/7/31
 * @module AdminActivityLotteryPrizeController
 * @author: su
 */
@Slf4j
@RestController
@RequestMapping("/admin/lottery-prize")
public class AdminActivityLotteryPrizeController {

    @Autowired
    private ActivityLotteryPrizeService activityLotteryPrizeService;

    /**
     * 分页查询 奖品列表
     */
    @PostMapping("/find-page")
    public QResult<Page<ActivityLotteryPrize>> findByPage(@RequestBody ActivityLotteryPrizeQueryVo queryVo) {
        return QResult.success(activityLotteryPrizeService.findByPage(queryVo));
    }

    /**
     * 查询奖品信息
     */
    @GetMapping("/info")
    public QResult<ActivityLotteryPrize> info(@RequestParam String id) {
        return QResult.success(activityLotteryPrizeService.findById(id));
    }


    /**
     * 根据id 查询奖品名称
     */
    @GetMapping("/find-name")
    public QResult<List<ActivityLotteryPrizeNameVo>> findNameByIds(@RequestParam String ids) {
        String[] idArr = ids.split(",");
        List<ActivityLotteryPrizeNameVo> nameArr = activityLotteryPrizeService.findNameByIds(idArr);
        return QResult.success(nameArr);
    }

    /**
     * 更新奖品
     */
    @PostMapping("/save")
    public QResult<ActivityLotteryPrize> save(@RequestBody ActivityLotteryPrize prize) {
        ActivityLotteryPrize save = activityLotteryPrizeService.save(prize);
        return QResult.success(save);
    }

    /**
     * 删除奖品
     */
    @PostMapping("/delete")
    public QResult delete(@RequestBody ActivityLotteryPrize prize) {
        activityLotteryPrizeService.delete(prize.getId());
        return QResult.success(true);
    }
}
